/**
 * Created by admin on 2017/10/26.
 */
$(document).ready(function () {

    var compare = function (obj1, obj2) {
        var val1 = obj1.ope_id;
        var val2 = obj2.ope_id;
        if (val1 < val2) {
            return -1;
        } else if (val1 > val2) {
            return 1;
        } else {
            return 0;
        }
    };
    
    var VAL = {
    	TOOLG_ID    : "$FMA",
    	NORMAL      : "0000000"  ,
    	EVT_USER    : $("#userId").text(),
    	T_FBPBISTOL : "FBPBISTOL",
    	T_FBPBISPTH : "FBPBISPTH",
    	T_FBPBISOPE : "FBPBISOPE",
    	T_FBPBISDAT : "FBPBISDAT",
    	T_FIPINQSHT : "FIPINQSHT",
    	T_FPPMOVEIN : "FPPMOVEIN",
    	T_FPPMOVEOUT: "FPPMOVEOUT",
        T_MIPSHTJUDGE: "MIPSHTJUDGE",
    	T_MIPINQMTRL: "MIPINQMTRL",
        DISABLED_ATTR: {
            'disabled': true
        },
        ENABLED_ATTR: {
            'disabled': false
        }
    };
    
    var domObj = {
        buttons : {
            $move_out_btn : $("#move_out_btn"),
            $clean_btn    : $("#clean_btn")
        },
        
        $toolIdSel       : $("#toolIdSel"),
        $prdSeqIdTxt     : $("#prdSeqIdTxt"),
        $radioOldMain    : $("#radioOldMain"),
        $radioNewMain    : $("#radioNewMain"),
        $radioToRework   : $("#radioToRework"),
        $toMainPathIdSel : $("#toMainPathIdSel"),
        $toMainOpeIdSel  : $("#toMainOpeIdSel"),
        $toReworkPathSel : $("#toReworkPathSel"),
        $defectCodeSel   : $("#defectCodeSel"),
        $remarkTxt       : $("#remarkTxt"),
        $radioOK : $("#radioOK"),
        $radioNG : $("#radioNG"),
        grids : {
            $prodListDiv : $("#prodListDiv"),
            $prodListGrd : $("#prodListGrd"),
            $prodListPg  : $("#prodListPg"),
            $mtrlListDiv : $("#mtrlListDiv"),
            $mtrlListGrd : $("#mtrlListGrd"),
            $mtrlListPg  : $("#mtrlListPg"),
            $defectJudgeDetailListDiv : $("#defectJudgeDetailListDiv"),
            $defectJudgeDetailListGrd : $("#defectJudgeDetailListGrd"),
            $defectJudgeDetailListPg : $("#defectJudgeDetailListPg")
        },
        
        dialogs: {            
            $defectDialog : $("#defectDialog"),
            $defectDialog_defectTypeSel : $("#defectDialog_defectTypeSel"),
            $defectDialog_defectListDiv : $("#defectDialog_defectListDiv"),
            $defectDialog_defectListGrd : $("#defectDialog_defectListGrd"),
            $defectDialog_defectListPg : $("#defectDialog_defectListPg"),
            $defectDialog_sureBtn : $("#defectDialog_sureBtn")
        }
    };
    
    /**
     * grid  initialization
     */
    var iniGridInfo = function() {
        domObj.grids.$prodListGrd.jqGrid({
	        url: "",
	        datatype: "local",
	        mtype: "POST",
	        autowidth: true,
	        shrinkToFit: false,
	        resizable: true,
	        loadonce: true,
	        viewrecords: true,
	        rownumbers: true,
	        rowNum: 20,
	        emptyrecords: true,
	        colModel: [
	            {
	                name: 'prd_seq_id',
	                index: 'prd_seq_id',
	                label: SHEET_ID_TAG,
	                width: 150
	            },  {
	                name: 'prd_stat',
	                index: 'prd_stat',
	                label: PRD_STAT_TAG,
	                width: 100
	            },{
	                name: 'prd_grade',
	                index: 'prd_grade',
	                label: PRD_GRADE_TAG,
	                width: 100
	            }, {
	                name: 'lot_id_fk',
	                index: 'lot_id_fk',
	                label: LOT_ID_TAG,
	                width: 150
	            }, {
	                name: 'wo_id_fk',
	                index: 'wo_id_fk',
	                label: WO_ID_TAG,
	                width: 150
	            },{
	                name: 'mdl_id_fk',
	                index: 'mdl_id_fk',
	                label: MDL_ID_TAG,
	                width: 200
	            }, {
	                name: 'path_id_fk',
	                index: 'path_id_fk',
	                label: PATH_ID_TAG,
	                width: 100
	            }, {
	                name: 'path_ver_fk',
	                index: 'path_ver_fk',
	                label: PATH_VER_TAG,
	                width: 100
	            }, {
	                name: 'ope_id_fk',
	                index: 'ope_id_fk',
	                label: OPE_ID_TAG,
	                width: 100
	            }, {
	                name: 'ope_no_fk',
	                index: 'ope_no_fk',
	                label: OPE_NO_TAG,
	                width: 100
	            },{
	                name: 'ope_ver_fk',
	                index: 'ope_ver_fk',
	                label: OPE_VER_TAG,
	                width: 100
	            }, {
	                name: 'proc_id_fk',
	                index: 'proc_id_fk',
	                label: PROC_ID_TAG,
	                width: 100
	            },{
	                name: 'tool_id_fk',
	                index: 'tool_id_fk',
	                label: TOOL_ID_TAG,
	                width: 100
	            },{
	            	name: 'logon_timestamp',   
	            	index: 'logon_timestamp',
	            	label: LOGON_TIMESTAMP_TAG, 
	            	width: 180}],
	        pager: "#prodListPg"
	    });
        domObj.grids.$mtrlListGrd.jqGrid({
	        url: "",
	        datatype: "local",
	        mtype: "POST",
	        autowidth: true,
	        shrinkToFit: true,
	        resizable: true,
	        loadonce: true,
	        viewrecords: true,
	        rownumbers: true,
	        rowNum: 20,
	        emptyrecords: true,
	        colModel: [
	            {
	                name: 'mtrl_cate',
	                index: 'mtrl_cate',
	                label: MTRL_CATE_TAG,
	                width: 100
	            },  {
	                name: 'mtrl_prod_id_fk',
	                index: 'mtrl_prod_id_fk',
	                label: MTRL_ID_TAG,
	                width: 200
	            },{
	                name: 'mtrl_batch',
	                index: 'mtrl_batch',
	                label: MTRL_LOT_ID_TAG,
	                width: 200
	            }, {
	                name: 'mtrl_qty',
	                index: 'mtrl_qty',
	                label: MTRL_QTY_TAG,
	                width: 100
	            }],
	        pager: "#mtrlListPg"
	    });
        domObj.grids.$defectJudgeDetailListGrd.jqGrid({
            url: "",
            datatype: "local",
            mtype: "POST",
            autowidth: false,
            shrinkToFit: true,
            resizable: true,
            loadonce: true,
            viewrecords: true,
            rownumbers: true,
            rowNum: 20,
            emptyrecords: true,
            colModel: [
                {
                    name: 'def_code',
                    index: 'def_code',
                    label: DEF_CODE_TAG,
                    width: 180
                }, {
                    name: 'def_code_desc',
                    index: 'def_code_desc',
                    label: DEF_DESC_TAG,
                    width: 350
                }],
            pager: "#defectJudgeDetailListPg"
        });
        domObj.dialogs.$defectDialog_defectListGrd.jqGrid({
            url: "",
            datatype: "local",
            mtype: "POST",
            autowidth: false,
            shrinkToFit: true,
            resizable: true,
            loadonce: true,
            viewrecords: true,
            rownumbers: true,
            rowNum: 20,
            emptyrecords: true,
            colModel: [
                {
                    name: 'data_id',
                    index: 'data_id',
                    label: DEF_CODE_TAG,
                    width: 180
                }, {
                    name: 'data_ext',
                    index: 'data_ext',
                    label: DEF_DESC_TAG,
                    width: 350
                }],
            pager: "#defectDialog_defectListPg"
        });
    };
	
    /**
     * All tool functions
     * @type {Object}
     */
    var toolFunc = {
    	resizeFnc : function(){
            var offsetBottom, grdDivWidth;
            grdDivWidth = $(".divTop").width();
            offsetBottom = $(window).height() - domObj.grids.$prodListDiv.offset().top;
            
            //prodList设置
            domObj.grids.$prodListDiv.width(grdDivWidth);
            domObj.grids.$prodListDiv.height(offsetBottom*0.17);
            domObj.grids.$prodListGrd.setGridWidth(grdDivWidth);
            domObj.grids.$prodListGrd.setGridHeight(offsetBottom*0.17-51);
            
            //mtrlList设置
            var grdDivWidth2 = $(".divTop2").width();
            var offsetBottom2 = $(window).height() - domObj.grids.$mtrlListDiv.offset().top;
            domObj.grids.$mtrlListDiv.width(grdDivWidth2);
            domObj.grids.$mtrlListDiv.height(offsetBottom2*0.4);
            domObj.grids.$mtrlListGrd.setGridWidth(grdDivWidth2);
            domObj.grids.$mtrlListGrd.setGridHeight(offsetBottom2*0.4-51);
            
            //mtrlList设置
            domObj.grids.$defectJudgeDetailListDiv.width(grdDivWidth2);
            domObj.grids.$defectJudgeDetailListDiv.height(offsetBottom2*0.4);
            domObj.grids.$defectJudgeDetailListGrd.setGridWidth(grdDivWidth2);
            domObj.grids.$defectJudgeDetailListGrd.setGridHeight(offsetBottom2*0.4-51);
    	},
        iniToolIdSel : function(){//根据FMA绑定的设备群组获取设备
            var inObj = {
                trx_id : VAL.T_FBPBISTOL,
                action_flg : "Q",
                iary : [{
                    tool_group_id_fk : VAL.TOOLG_ID
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                SelectDom.addSelectArr_(domObj.$toolIdSel, outObj.oary, "tool_id","tool_id","tool_dsc",true);
            }
        },
        /**
         * 初始化主工艺路线
         */
        iniPathInfo : function($SelectObj, path_cate){
            var inObj = {
                trx_id: VAL.T_FBPBISPTH,
                action_flg: 'Q',
                iaryA: [{
                	path_cate: path_cate
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                outObj.oaryA.sort(compare);
                var options = [];
                for(var i=0;i<outObj.oaryA.length;i++){
                	if(path_cate == "RWK" && outObj.oaryA[i]['path_id'] == "REWFMA01"){
                		continue;
                	}
                    options[i] = "<option value ="+ outObj.oaryA[i]['path_id'] 
                    	+ "@" + outObj.oaryA[i]['path_ver']
                    	+ ">" + outObj.oaryA[i]['path_id']+":"+ outObj.oaryA[i]['path_dsc']+ "</option>";
                }
                $SelectObj.append(options.join(""));
                $SelectObj.select2({
                    theme : "bootstrap"
                });
            }
        },
        iniOpeIdSel : function(){
        	SelectDom.initWithSpace(domObj.$toMainOpeIdSel);
        	var pathInfo = $.trim(domObj.$toMainPathIdSel.val());
        	if(!pathInfo){
                return false;
        	}
        	var pathAry = pathInfo.split("@");
            var inObj = {
                trx_id : VAL.T_FBPBISOPE,
                action_flg : "P",
                iary : [{
                	path_id : pathAry[0],
                	path_ver : pathAry[1]
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                outObj.oary.sort(compare);
                var options = [];
                for(var i=0;i<outObj.oary.length;i++){
                    options[i] = "<option value ="+ outObj.oary[i]['ope_no'] 
                		+ "@" + outObj.oary[i]['ope_id']
                    	+ "@" + outObj.oary[i]['ope_ver']
                    	+ ">" + outObj.oary[i]['ope_id']+":"+ outObj.oary[i]['ope_dsc']+ "</option>";
                }
                domObj.$toMainOpeIdSel.append(options.join(""));
                domObj.$toMainOpeIdSel.select2({
                    theme : "bootstrap"
                });
            }
        },
    	/***************************初始化等级Dialog***************************/
    	iniDefectDialogFunc : function(){
		      /*****
	        当多次弹出对话框的同时也会多次绑定click事件。
	        解决办法: 在show Dialog时将click unbind全部掉
	                  然后再绑定，这样就只剩下一个click事件了。
	      **********/
    		domObj.dialogs.$defectDialog.unbind('shown.bs.modal');
		    domObj.dialogs.$defectDialog_sureBtn.unbind('click');
    		domObj.dialogs.$defectDialog_defectTypeSel.select2({
    			theme : "bootstrap",
    	        width : $(window).width()* 0.12
    	    });
      		domObj.dialogs.$defectDialog_sureBtn.bind('click', btnFunc.defect_sure_func);
		    domObj.dialogs.$defectDialog.modal('show');
    	},
    	iniDefectInfo : function(){
            var inObj = {
                trx_id: VAL.T_FBPBISDAT,
                action_flg: "1",
                distinct_item : "EXT_2",
                iary: [{
                    data_cate : "DFCT"
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
            	SelectDom.addSelectArr(domObj.dialogs.$defectDialog_defectTypeSel, outObj.oaryB, "distinct_data", "distinct_data", true, true);
            }else{
            	return false;
            }
            if(!toolFunc.iniDefectListInfo()){
            	return false;
            }
            return true;
    	},
    	iniDefectListInfo : function(){
            var inObj = {
                trx_id: VAL.T_FBPBISDAT,
                action_flg: "Q",
                iary: [{
                    data_cate : "DFCT",
                    ext_2 : $.trim(domObj.dialogs.$defectDialog_defectTypeSel.val())
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                setGridInfo(outObj.oary, "#defectDialog_defectListGrd");
            }
    	},
        iniPrdJudListInfo : function(){
            var prd_seq_id = $.trim(domObj.$prdSeqIdTxt.val());
            var inObj = {
                trx_id     : VAL.T_MIPSHTJUDGE,
                action_flg : "Q",
                prd_seq_id : prd_seq_id
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                setGridInfo(outObj.oaryA, "#defectJudgeDetailListGrd");
            }
        },
        queryPrdInfo : function(){
        	var prd_seq_id = $.trim(domObj.$prdSeqIdTxt.val());
        	if(!prd_seq_id){
                showErrorDialog("", "请输入屏体代码");
                return false;
        	}
            var tool_id = $.trim(domObj.$toolIdSel.val());
            if(!tool_id){
                showErrorDialog("", "请选择设备代码");
                return false;
            }
            var inObj = {
                trx_id     : VAL.T_FIPINQSHT,
                action_flg : "Q",
                prd_seq_id : prd_seq_id
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
            	setGridInfo(outObj, "#prodListGrd");
            	if(outObj.toolg_id_fk !== VAL.TOOLG_ID){
                    showErrorDialog("", "屏体设备群组不匹配，屏体设备群组为[" + outObj.toolg_id_fk + "],必须为[" + VAL.TOOLG_ID + "]");
                    return false;
            	}
            	if(outObj.prd_stat !== "WAIT" && outObj.prd_stat !== "INPR"){
                    showErrorDialog("", "屏体状态不正确，必须为[WAIT]或者[INPR],当前状态为[" + outObj.prd_stat + "]");
                    return false;
            	}else if(outObj.prd_stat == "WAIT"){
            		/*********************入账**********************/
            		if(!btnFunc.move_in_func(outObj)){
            			return false;
            		}
            	}
            	
            	/*********************获取屏体绑定物料信息**********************/
            	toolFunc.queryPrdMtrlInfo(prd_seq_id);
                /*********************初始化不良信息**********************/
        		SelectDom.initWithSpace(domObj.dialogs.$defectDialog_defectTypeSel);
        		domObj.dialogs.$defectDialog_defectListGrd.jqGrid("clearGridData");
        		if(toolFunc.iniDefectInfo()){
        			return false;
        		}
                /*********************初始化判定不良明细**********************/
                toolFunc.iniPrdJudListInfo();
            }else{
            	return false;
            }
        },
        queryPrdMtrlInfo : function(prd_seq_id){
        	var inObj = {
                trx_id     : VAL.T_MIPINQMTRL,
                action_flg : "Q",
                prd_seq_id : prd_seq_id
            };
        	var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
            	setGridInfo(outObj.oary, "#mtrlListGrd");
            }
        }
    };
    
    /**
     * All button click function
     * @type {Object}
     */
    var btnFunc = {
    	move_in_func : function(prdInfo){
        	var prd_seq_id = $.trim(domObj.$prdSeqIdTxt.val());
        	if(!prd_seq_id){
                showErrorDialog("", "请输入屏体代码");
                return false;
        	}

            var tool_id = $.trim(domObj.$toolIdSel.val());
            if(!tool_id){
                showErrorDialog("", "请选择设备代码");
                return false;
            }
            
            var inObj = {
                trx_id     : VAL.T_FPPMOVEIN,
                evt_usr    : VAL.EVT_USER,
                action_flg : "A",
                opi_ope_flg: "Y",
                iary       : [{
                	prd_seq_id : prd_seq_id,
                	tool_id_fk : tool_id
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
            	prdInfo.prd_stat = "INPR";
            	setGridInfo(prdInfo, "#prodListGrd");
            }else{
            	return false;
            }
            
            return true;
    	},
        clean_func: function () {
        	iniContorlData();
            domObj.grids.$prodListGrd.jqGrid("clearGridData");
            domObj.grids.$mtrlListGrd.jqGrid("clearGridData");
            domObj.grids.$defectJudgeDetailListGrd.jqGrid("clearGridData");
            domObj.dialogs.$defectDialog_defectListGrd.jqGrid("clearGridData");
            domObj.dialogs.$gradeDialog_gradeListGrd.jqGrid("clearGridData");
        },
        radio_old_main_func : function(){
        	domObj.$toMainPathIdSel.attr(VAL.DISABLED_ATTR);
        	domObj.$toMainOpeIdSel.attr(VAL.DISABLED_ATTR);
        	domObj.$toReworkPathSel.attr(VAL.DISABLED_ATTR);
            /**************清空主工艺路线\重工工艺****************/
            SelectDom.initWithSpace(domObj.$toReworkPathSel);
            SelectDom.initWithSpace(domObj.$toMainPathIdSel);
            SelectDom.initWithSpace(domObj.$toMainOpeIdSel);
        },
        radio_new_main_func : function(){
        	domObj.$toMainPathIdSel.attr(VAL.ENABLED_ATTR);
        	domObj.$toMainOpeIdSel.attr(VAL.ENABLED_ATTR);
        	domObj.$toReworkPathSel.attr(VAL.DISABLED_ATTR);
            /**************清空重工工艺****************/
            SelectDom.initWithSpace(domObj.$toReworkPathSel);
            /**********************初始化主工艺路线*************************/
        	toolFunc.iniPathInfo(domObj.$toMainPathIdSel, "MAN");
        },
        radio_rework_func : function(){
        	domObj.$toMainPathIdSel.attr(VAL.DISABLED_ATTR);
        	domObj.$toMainOpeIdSel.attr(VAL.DISABLED_ATTR);
        	domObj.$toReworkPathSel.attr(VAL.ENABLED_ATTR);
            /**************清空主工艺路线信息****************/
            SelectDom.initWithSpace(domObj.$toMainPathIdSel);
            SelectDom.initWithSpace(domObj.$toMainOpeIdSel);
            /*******************初始化重工工艺路线*********************/
            toolFunc.iniPathInfo(domObj.$toReworkPathSel, "RWK");
        },
        defect_sure_func : function(){
        	var rowId = domObj.dialogs.$defectDialog_defectListGrd.jqGrid('getGridParam','selrow');
        	if(!rowId){
        		showErrorDialog("", "请选择不良代码");
        		return false;
        	}
        	var rowData = domObj.dialogs.$defectDialog_defectListGrd.jqGrid("getRowData", rowId);
        	SelectDom.initWithValTxt(domObj.$defectCodeSel, rowData['data_id'], rowData['data_id']);
        	domObj.dialogs.$defectDialog.modal('hide');
        },
    	move_out_func : function(){
    		var repair_flg;
        	var rowIds = domObj.grids.$prodListGrd.jqGrid('getDataIDs');
    		if(rowIds.length <= 0){
    			showErrorDialog("","请输入需要出账的屏体代码，并按回车键获取屏体信息！");
    			return false;
    		}
    		var rowData = domObj.grids.$prodListGrd.jqGrid('getRowData',rowIds[0]);

            var tool_id = $.trim(domObj.$toolIdSel.val());
            if(!tool_id){
                showErrorDialog("", "请选择设备代码");
                return false;
            }
            
            if(domObj.$radioNewMain.attr("checked") == "checked"){
            	repair_flg = "N";
            	if(!$.trim(domObj.$toMainPathIdSel.val())){
                    showErrorDialog("", "请选择自定义的主工艺路线");
                    return false;	
            	}
            	if(!$.trim(domObj.$toMainOpeIdSel.val())){
                    showErrorDialog("", "请选择自定义的主工艺路线站点");
                    return false;
            	}
            }else if(domObj.$radioToRework.attr("checked") == "checked"){
            	repair_flg = "R";
            	if(!$.trim(domObj.$toReworkPathSel.val())){
                    showErrorDialog("", "请选择重工工艺");
                    return false;	
            	}
            }else{
            	repair_flg = "O";
            }
            var okng;
            if(domObj.$radioOK.attr("checked") == "checked") {
                okng = "OK";
            }else{
                okng = "NG";
            }
            
            var mainPathAry = $.trim(domObj.$toMainPathIdSel.val()).split("@");
            var mainOpeAry = $.trim(domObj.$toMainOpeIdSel.val()).split("@");
            var rwkAry = $.trim(domObj.$toReworkPathSel.val()).split("@");
            var inObj = {
                trx_id     : VAL.T_FPPMOVEOUT,
                evt_usr    : VAL.EVT_USER,
                action_flg : "T",
                opi_ope_flg: "Y",
            	repair_flg : repair_flg,
                iary       : [{
                	prd_seq_id : rowData['prd_seq_id'],
                	tool_id_fk : tool_id,
                	new_route_id : mainPathAry[0],
                	new_route_ver : mainPathAry[1],
                	new_ope_no : mainOpeAry[0],
                	new_ope_id : mainOpeAry[1],
                	new_ope_ver : mainOpeAry[2],
                	rwk_route_id : rwkAry[0],
                	rwk_route_ver : rwkAry[1],
                	defect_code : $.trim(domObj.$defectCodeSel.val()),
                	sht_ope_msg : $.trim(domObj.$remarkTxt.val()),
                    ext_9 : okng
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
            	domObj.grids.$prodListGrd.jqGrid("clearGridData");
            	domObj.grids.$mtrlListGrd.jqGrid("clearGridData");
            	showMessengerSuccessDialog("出账成功！",1);
                domObj.$prdSeqIdTxt.val("");
                domObj.$prdSeqIdTxt.focus();
            }
    	}
    };
    
    /**
     * Bind button click action
     */
    var iniButtonAction = function(){
        domObj.buttons.$clean_btn.click(function(){
        	btnFunc.clean_func();
        });
        domObj.$radioOldMain.click(function(){
        	btnFunc.radio_old_main_func();        	
        });
        domObj.$radioNewMain.click(function(){
        	btnFunc.radio_new_main_func();
        });
        domObj.$radioToRework.click(function(){
        	btnFunc.radio_rework_func();
        });
        domObj.$defectCodeSel.on("select2:opening",function(e){
            toolFunc.iniDefectDialogFunc();
        });
        domObj.buttons.$move_out_btn.click(function(){
        	btnFunc.move_out_func();
        });
    };
    
    /**
     * Ini contorl's data
     */
    var iniContorlData = function(){
    	$("input").val("");
    	SelectDom.initWithSpace($("select"));
    	domObj.$radioOldMain.attr("checked","checked");
    	btnFunc.radio_old_main_func();
        toolFunc.iniToolIdSel();
    };
    
    var otherActionBind = function(){
        //Stop from auto commit
        $("form").submit(function(){
            return false;
        });
        
        $(window).resize(function() {
        	toolFunc.resizeFnc();
        });
        
        domObj.$prdSeqIdTxt.keydown(function(event){
            if(event.keyCode==13){
            	toolFunc.queryPrdInfo();
            }
        });
        
        domObj.dialogs.$defectDialog_defectTypeSel.change(function(){
        	toolFunc.iniDefectListInfo();
        });
        
        domObj.$toMainPathIdSel.change(function(){
        	toolFunc.iniOpeIdSel();
        });
    };
    
    /**
     * Ini view, data and action bind
     */
    var initializationFunc = function(){
    	iniGridInfo();
    	toolFunc.resizeFnc();
    	iniContorlData();
    	iniButtonAction();
    	otherActionBind();
    };
    
    initializationFunc();
});
